package com.pd;

import com.pd.pojo.PdOrder;
import com.pd.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "orderQueue")
public class OrderConsumer {
    @Autowired
    private OrderService orderService;

    //配合@RabbitHandler,指定处理消息的方法，一个类中只能有一个@RabbitHandler
    @RabbitHandler
    public void receive(PdOrder order) throws Exception {
        orderService.saveOrder(order);//将接收到的信息存储到数据库
        System.out.println("-------------订单已入库！------------");
    }
}
